package org.gdkm.springbootxiangmushizhan.controller.admin;

import com.github.pagehelper.PageInfo;
import org.gdkm.springbootxiangmushizhan.domain.vo.CommentAdminVO;
import org.gdkm.springbootxiangmushizhan.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/admin/comment")
public class CommentAdminController {
    @Autowired
    private ICommentService commentService;

    // 跳转到评论管理页面，分页查询
    @GetMapping("")
    public String list(@RequestParam(value = "page", defaultValue = "1") int page,
                      @RequestParam(value = "count", defaultValue = "10") int count,
                      HttpServletRequest request) {
        PageInfo<CommentAdminVO> pageInfo = commentService.getAllCommentsWithArticleTitle(page, count);
        request.setAttribute("comments", pageInfo);
        return "back/comment_list";
    }

    // 删除评论
    @PostMapping("/delete")
    @ResponseBody
    public String delete(@RequestParam Integer id) {
        commentService.deleteCommentById(id);
        return "ok";
    }

    // 隐藏/显示评论
    @PostMapping("/status")
    @ResponseBody
    public String updateStatus(@RequestParam Integer id, @RequestParam String status) {
        commentService.updateCommentStatusById(id, status);
        return "ok";
    }
} 